#!/usr/local/bin/python
#
#  Main.py
#  TwoHand
#
#  Created by Pete Lord on 16/12/2008.
#  Copyright (c) 2008 . All rights reserved.
#

import pygame, math, random, Options, Ships, Views, Entities

pygame.init()

flags = False


clock = pygame.time.Clock()
# define which keys we're looking for, store data on their state.
keysHeld = {pygame.K_ESCAPE:False, pygame.K_LEFT:False, pygame.K_RIGHT:False, pygame.K_UP:False, pygame.K_DOWN:False, pygame.K_a:False, pygame.K_s:False}

def main():

    # running the game by default.
    running = True
    
    # init
    entities = Entities.GameEntities()
    view = Views.View(entities)
    blurScreen = pygame.Surface((Options.SCREEN_WIDTH, Options.SCREEN_HEIGHT), flags, view.screen)
    # create the player ship.
    entities.shipsLayer2.append(Ships.Player(entities, view.screen, 400, 400, 0))
    player = entities.shipsLayer2[0]
    
    while running:    
        clock.tick(60) # 60 fps.
        pygame.msg.message
        
        # Code to toggle the state of keys. Roll with it.
        for event in pygame.event.get(pygame.KEYDOWN):
            keysHeld[event.key] = True
        for event in pygame.event.get(pygame.KEYUP):
            keysHeld[event.key] = False
            
        # quit?
        if keysHeld[pygame.K_ESCAPE]:
            running = False
            
        # Player ship movement.
        if keysHeld[pygame.K_LEFT]:
            player.moveLeft()
            
        if keysHeld[pygame.K_RIGHT]:
            player.moveRight()
            
        if keysHeld[pygame.K_UP]:
            player.moveUp()
            
        if keysHeld[pygame.K_DOWN]:
            player.moveDown()
        
        if keysHeld[pygame.K_a]:
            player.weaponA.OrderFire = True
        else:
            player.weaponA.OrderFire = False
            
        if keysHeld[pygame.K_s]:
            player.weaponB.OrderFire = True
        else:
            player.weaponB.OrderFire = False
            
        # Poll entities! -------------->>>
        entities.poll()
        # Poll entities! --------------<<<
            
        # Draw Loop ----------------------------------------------------------------------------------------------------->>>
        view.screen.fill((0, 0 ,0)) # blackout!
        view.screen.blit(blurScreen, (0, 0))         # blur code!!!
        
        entities.draw() # draw ships & projectiles. to be replaced with layers, but not yet.
        
        pygame.display.flip()
        
        blurScreen = view.screen.copy()# this needs to go before unblurry aspects are drawn.
        
        blurScreen.set_alpha(254) # 50 is meh, 100 is a bit ew looking, more is mad.
        # Draw Loop -----------------------------------------------------------------------------------------------------<<<
    pygame.quit()
    print "Goobye!"
    
main()